﻿@using Microsoft.AspNetCore.Localization
@inject IConfiguration configuration
@inject CommonLocalizationService CL
@inject Chino.IdentityServer.Services.Localization.IJsonLocalizationService JL
@inject Chino.IdentityServer.Configures.ChinoAccountConfiguration AccountConfiguration

@using IdentityServer4.Extensions

@{
    string userDisplayName = Context.User?.GetDisplayName();
    bool showSignInOut = (bool)(ViewData["Nav_ShowLogin/Out"] ?? true);

    var currentCulture = Context.Features.Get<IRequestCultureFeature>()?.RequestCulture?.UICulture;


    bool IsUserLayout()
    {
        var layout = ViewData["_layout"];
        if (layout == null)
            return false;

        return (string)layout == "user";
    }
}

<div class="nav-page">
    <nav class="navbar navbar-expand-lg navbar-dark bg-dark navbar-expand-sm navbar-toggleable-sm border-bottom box-shadow mb-3">
        <div class="container">
            <a class="navbar-brand" asp-area="" asp-page="/Index">
                @JL[(configuration["Chino:NavTitle"] ?? "Chino"),currentCulture]
            </a>
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
                    aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
                <ul class="navbar-nav flex-grow-1">
                    @if (User.Identity.IsAuthenticated)
                    {
                        <li class="nav-item">
                            <a class="nav-link @(IsUserLayout()?"active":string.Empty)" aria-current="page" asp-page="/User/Index">@CL["nav_userpage"]</a>
                        </li>
                        @if (showSignInOut)
                        {
                            <li class="nav-item dropdown ml-lg-auto ml-md-auto">
                                <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown">@userDisplayName <b class="caret"></b></a>

                                <div class="dropdown-menu">
                                    <a class="dropdown-item" asp-page="/Account/Logout">@CL["logout"]</a>
                                </div>
                            </li>
                        }
                    }
                    else
                    {
                        @if (showSignInOut)
                        {
                            <li class="nav-item ml-lg-auto ml-md-auto">
                                <a class="nav-link" asp-page="/Account/Login">@CL["login"]</a>
                            </li>
                            if (AccountConfiguration.EnableRegister)
                            {
                                <li class="nav-item">
                                    <a class="nav-link" asp-page="/Account/Register">@CL["register"]</a>
                                </li>
                            }
                        }
                    }
                    @*<li class="nav-item">
                            <a class="nav-link text-dark" asp-area="" asp-page="/Index">Home</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
                        </li>*@
                </ul>
            </div>
        </div>
    </nav>
</div>